﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.ValentineUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.sim.*;
    import org.aswing.geom.*;
    import Display.*;
    import flash.text.*;
    import Display.aswingui.*;
    import Modules.stats.types.*;

    public class ValentineDialogView extends GenericDialogView {

        public static const TAB_STATE_SELECTED:int = 0;
        public static const TAB_STATE_UNSELECTED:int = 1;
        public static const TAB_WIDTH:int = 221;
        public static const TAB_HEIGHT:int = 37;
        public static const TAB_CAP_FONT_SIZE:int = 22;
        public static const TAB_FONT_SIZE:int = 16;

        protected var m_contentPanel:JPanel;
        protected var m_items:Array;
        protected var m_tabStates:Array;
        protected var m_tabs:Array;
        protected var m_dataDict:Dictionary;
        protected var m_makerPanel:MakerPanel;

        public function ValentineDialogView(_arg1:Dictionary, _arg2:String="", _arg3:String="", _arg4:int=0, _arg5:Function=null, _arg6:String="", _arg7:int=0){
            super(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7);
            this.setLayout(new SoftBoxLayout(SoftBoxLayout.Y_AXIS));
        }
        override protected function init():void{
            m_bgAsset = m_assetDict["dialog_bg"];
            m_titleSmallCapsFontSize = 38;
            this.m_tabStates = new Array();
            this.m_tabStates.push(ValentineDialog.assetDict["tab_selected"]);
            this.m_tabStates.push(ValentineDialog.assetDict["tab_unselected"]);
            this.m_dataDict = Global.gameSettings.getValentinesAssets();
            this.makeBackground();
            this.makeCenterPanel();
            ASwingHelper.prepare(this);
        }
        override protected function makeBackground():void{
            if (m_bgAsset){
                ASwingHelper.setSizedBackground(this, m_bgAsset);
            };
        }
        override protected function makeCenterPanel():void{
            ASwingHelper.setBackground(this, m_bgAsset);
            this.m_contentPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.append(ASwingHelper.verticalStrut(10));
            this.append(this.createHeaderPanel());
            this.append(this.makeTabsPanel());
            this.append(ASwingHelper.verticalStrut(-3));
            this.append(this.m_contentPanel);
            ASwingHelper.prepare(this);
        }
        override protected function createHeaderPanel():JPanel{
            var _local1:JPanel = new JPanel(new BorderLayout());
            var _local2:JPanel = this.createCloseButtonPanel();
            var _local3:JPanel = this.createTitlePanel();
            var _local4:JPanel = this.createHeartPanel();
            ASwingHelper.prepare(_local2);
            ASwingHelper.prepare(_local4);
            var _local5:Number = (_local4.getWidth() - _local2.getWidth());
            var _local6:JPanel = ASwingHelper.makeSoftBoxJPanel();
            ASwingHelper.setEasyBorder(_local2, 5, 5);
            _local6.appendAll(ASwingHelper.horizontalStrut(_local5), _local2);
            _local1.append(_local4, BorderLayout.WEST);
            _local1.append(_local3, BorderLayout.CENTER);
            _local1.append(_local6, BorderLayout.EAST);
            return (_local1);
        }
        override protected function createTitlePanel():JPanel{
            var _local1:JPanel;
            _local1 = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            m_titleFontSize = TextFieldUtil.getLocaleFontSize(30, 20, null);
            var _local2:String = ZLoc.t("Dialogs", (m_titleString + "_title"));
            title = ASwingHelper.makeTextField(_local2, EmbeddedArt.TITLE_FONT, m_titleFontSize, EmbeddedArt.darkPinkTextColor, 3);
            title.filters = EmbeddedArt.valtitleFilters;
            var _local3:TextFormat = new TextFormat();
            _local3.size = m_titleSmallCapsFontSize;
            TextFieldUtil.formatSmallCaps(title.getTextField(), _local3);
            _local1.append(title);
            title.getTextField().height = (m_titleFontSize * 1.5);
            ASwingHelper.setEasyBorder(_local1, 4);
            return (_local1);
        }
        override protected function createCloseButtonPanel():JPanel{
            var _local1:JPanel = new JPanel(ASwingHelper.softBoxLayoutVertical);
            var _local2:JButton = ASwingHelper.makeMarketCloseButton();
            _local2.addEventListener(MouseEvent.CLICK, onCancel, false, 0, true);
            _local1.append(_local2);
            ASwingHelper.setEasyBorder(_local2, 4, 3, 0, 3);
            return (_local1);
        }
        protected function createHeartPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.RIGHT);
            var _local2:JLabel = ASwingHelper.makeLabel(String(ValentineManager.getTotalAdmirers()), EmbeddedArt.TITLE_FONT, 24);
            _local2.setPreferredWidth(55);
            var _local3:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT);
            ASwingHelper.setBackground(_local3, (new (ValentineDialog.assetDict["admirersBG"])() as DisplayObject));
            _local3.setPreferredHeight(31);
            _local3.setMaximumHeight(31);
            _local3.setMinimumHeight(31);
            ASwingHelper.setEasyBorder(_local3, 10);
            var _local4:JLabel = ASwingHelper.makeLabel(ZLoc.t("Dialogs", "ValUI_admirers", {amount:""}), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, EmbeddedArt.redTextColor);
            _local3.append(_local4, ASwingHelper.horizontalStrut(10));
            ASwingHelper.setEasyBorder(_local1, 10);
            _local1.appendAll(ASwingHelper.horizontalStrut(10), _local2, _local3);
            return (_local1);
        }
        protected function makeTabsPanel():JPanel{
            var _local3:JPanel;
            var _local4:JPanel;
            var _local5:JTextField;
            var _local6:TextFormat;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER, 4);
            this.m_tabs = [ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER), ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER), ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER)];
            var _local2:int;
            while (_local2 < this.m_tabs.length) {
                _local3 = this.m_tabs[_local2];
                _local3.setPreferredSize(new IntDimension(TAB_WIDTH, TAB_HEIGHT));
                _local3.setMinimumSize(new IntDimension(TAB_WIDTH, TAB_HEIGHT));
                _local3.setMaximumSize(new IntDimension(TAB_WIDTH, TAB_HEIGHT));
                _local4 = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
                _local5 = ASwingHelper.makeTextField(ZLoc.t("Dialogs", ("ValUI_TabLabel_" + _local2)), EmbeddedArt.TITLE_FONT, TAB_FONT_SIZE, EmbeddedArt.pinkTextColor);
                _local6 = new TextFormat();
                _local6.size = TAB_CAP_FONT_SIZE;
                TextFieldUtil.formatSmallCaps(_local5.getTextField(), _local6);
                _local4.append(_local5);
                _local5.getTextField().height = (TAB_FONT_SIZE * 1.5);
                _local3.append(_local4);
                _local1.append(_local3);
                _local3.addEventListener(MouseEvent.MOUSE_UP, this.onTabClicked, false, 0, true);
                _local2++;
            };
            this.setSelectedTab(ValentineDialog.DEFAULT_TAB, false);
            ASwingHelper.setEasyBorder(_local1, 0, 33, 0, 10);
            return (_local1);
        }
        protected function createContentPanel(_arg1:String):JPanel{
            var _local2:JPanel = ASwingHelper.makeFlowJPanel();
            var _local3:JLabel = ASwingHelper.makeLabel(_arg1, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 36, EmbeddedArt.redTextColor);
            _local2.append(_local3);
            return (_local2);
        }
        protected function createMakerPanel():JPanel{
            if (this.m_makerPanel == null){
                this.m_makerPanel = new MakerPanel(this.m_dataDict);
                this.m_makerPanel.addEventListener(MakerPanel.PREPARE, this.preparePane, false, 0, true);
            };
            return (this.m_makerPanel);
        }
        protected function createAdmirersPanel():JPanel{
            var _local1:AdmirersPanel = new AdmirersPanel();
            _local1.addEventListener(MakerPanel.PREPARE, this.preparePane, false, 0, true);
            return (_local1);
        }
        protected function createAchievementsPanel():JPanel{
            var _local1:AchievementsPanel = new AchievementsPanel();
            _local1.addEventListener(MakerPanel.PREPARE, this.preparePane, false, 0, true);
            return (_local1);
        }
        protected function preparePane(_arg1:Event):void{
            ASwingHelper.prepare(this.parent);
        }
        public function setSelectedTab(_arg1:int, _arg2:Boolean):void{
            var _local3:JPanel;
            var _local4:String;
            for each (_local3 in this.m_tabs) {
                _local3.setBackgroundDecorator(new AssetBackground((new (this.m_tabStates[TAB_STATE_UNSELECTED])() as DisplayObject)));
            };
            this.m_tabs[_arg1].setBackgroundDecorator(new AssetBackground((new (this.m_tabStates[TAB_STATE_SELECTED])() as DisplayObject)));
            this.m_contentPanel.removeAll();
            _local4 = "unknown";
            switch (_arg1){
                case ValentineDialog.TAB_MAKE:
                    this.m_contentPanel.appendAll(this.createMakerPanel());
                    _local4 = StatsPhylumType.CARDMAKER;
                    break;
                case ValentineDialog.TAB_ADMIRE:
                    this.m_contentPanel.appendAll(this.createAdmirersPanel());
                    _local4 = StatsPhylumType.ADMIRERS;
                    break;
                case ValentineDialog.TAB_ACHIEVE:
                    this.m_contentPanel.appendAll(this.createAchievementsPanel());
                    _local4 = StatsPhylumType.PRIZES;
                    break;
            };
            ASwingHelper.prepare(this.parent);
            if (_arg2){
                StatsManager.count(StatsCounterType.CARDMAKER, StatsKingdomType.VDAY_2011, _local4, "tab_click");
            };
        }
        protected function onTabClicked(_arg1:MouseEvent):void{
            var _local2:int;
            while (_local2 < this.m_tabs.length) {
                if (this.m_tabs[_local2] == _arg1.currentTarget){
                    this.setSelectedTab(_local2, true);
                    break;
                };
                _local2++;
            };
        }

    }
}//package Display.ValentineUI 
